package com.denso.workflow.common;

import com.xiaoleilu.hutool.date.DateUtil;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by lijian on 2017/10/22.
 */
public class Tools {

    public static Date convertDate(int hour, int minute) {
        Calendar time = Calendar.getInstance();
        time.set(time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH), hour, minute, 0);
        return time.getTime();
    }

    public static String getTimeScope(Date date) {
        String time1 = DateUtil.format(date, "HH:mm");
        String time2 = DateUtil.format(DateUtil.offsetMinute(date, 10), "HH:mm");
        return time1 + " - " + time2;
    }

    public static String getDateTimeStr(Date date) {
        return DateUtil.format(date, "MM/dd HH:mm");
    }

    public static String getDateStr(Date date) {
        return DateUtil.format(date, "yyyy-MM-dd");
    }

    public static String formatTime(int hour, int minute) {
        String hourStr = Integer.toString(hour);
        if(hour < 10) {
            hourStr = "0" + hourStr;
        }
        String minuteStr = Integer.toString(minute);
        if(minute < 10) {
            minuteStr = "0" + minuteStr;
        }
        return hourStr + ":" + minuteStr;
    }


    public static String getAdminTypeStr(Object type) {
        int iType = 0;
        if(type instanceof Integer) {
            iType = (Integer)type;
        }
        if(type instanceof String) {
            iType = Integer.parseInt((String)type);
        }
        return (iType == 0) ? "门卫管理员" : "库房管理员";
    }

    public static boolean isLate(Date planTime) {
        Date now = new Date();
        Date timeLine = DateUtil.offsetMinute(planTime, 10);
        return now.after(timeLine);
    }
}
